package com.logos.musicframe.controller;

import com.logos.musicframe.req.SongsPlaylistReq;
import com.logos.musicframe.result.Result;
import com.logos.musicframe.service.SongsPlaylistService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 歌曲与歌单映射表(SongsPlaylist)表控制层
 *
 * @author rose
 * @since 2025-06-14 21:31:49
 */
@Component
@Slf4j
public class SongsPlaylistController {
    /**
     * 服务对象
     */
    @Autowired
    private SongsPlaylistService songsPlaylistService;


    /**
     * 添加歌曲到歌单中
     * @param songId
     * @param playlistId
     * @return
     */
    public Result<Boolean> addSong(Integer songId, Integer playlistId){
        try {
            log.info("PlaylistController.addSong.songId:{},playlistId:{}", songId, playlistId);
            SongsPlaylistReq songsPlaylistReq = new SongsPlaylistReq()
                    .setSongId(songId)
                    .setPlaylistId(playlistId);
            Boolean result = songsPlaylistService.addSong(songsPlaylistReq);
            return Result.ok(result);
        }catch (Exception e){
            log.error("PlaylistController.addSong.error{}", e.getMessage(), e);
            return Result.fail("添加歌曲到歌单失败");
        }
    }

    /**
     * 检查歌曲是否已经存在于歌单中
     * @param songId
     * @param playlistId
     * @return
     */
    public Result<Boolean> checkSongExistsInPlaylist(Integer songId, Integer playlistId) {
        try {
            log.info("PlaylistController.checkSongExistsInPlaylist.songId:{},playlistId:{}", songId, playlistId);
            Boolean exists = songsPlaylistService.checkSongExists(songId, playlistId);
            return Result.ok(exists);
        } catch (Exception e) {
            log.error("PlaylistController.checkSongExistsInPlaylist.error{}", e.getMessage(), e);
            return Result.fail("检查歌曲是否存在于歌单失败");
        }
    }
}

